
//两种写法函数，定义了函数的类型以及返回值,没有返回任何值须指定返回值类型为 void
function add(x: number, y: number): number {
    return x + y;
}
let myAdd = function(x: number, y: number): number { return x+y; };

// 书写完整函数类型
let myAdds: (baseValue:number, increment:number) => number =function(x: number, y: number): number { return x + y; };



function buildName(firstName: string, ...restOfName: string[]) {
  return firstName + " " + restOfName.join(" ");
}

// let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie");
let buildNameFun: (fname: string, ...rest: string[]) => string = buildName;



// 泛型

// 类型变量，它是一种特殊的变量，只用于表示类型而不是值。
function identity<T>(arg: T): T {
    return arg;
}
let output = identity<string>("myString");
let output1 = identity("myString");//也可这样写，利用了类型推论
// console.log(output);


function loggingIdentity<T>(arg: T[]): T[] {
    console.log(arg.length);  // Array has a .length, so no more error
    return arg;
}
let output2 = loggingIdentity([1,2,2,3,4]);
let output3 : <U>(arg:U)=>U=identity;//泛型类型
console.log(output2);
